#ifndef __spi_mpc83xx_h__
#define __spi_mpc83xx_h__
/**HEADER********************************************************************
* 
* Copyright (c) 2008 Freescale Semiconductor;
* All Rights Reserved
*
* Copyright (c) 2004-2008 Embedded Access Inc.;
* All Rights Reserved
*
* Copyright (c) 1989-2008 ARC International;
* All Rights Reserved
*
*************************************************************************** 
*
* THIS SOFTWARE IS PROVIDED BY FREESCALE "AS IS" AND ANY EXPRESSED OR 
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  
* IN NO EVENT SHALL FREESCALE OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 
* THE POSSIBILITY OF SUCH DAMAGE.
*
**************************************************************************
*
* $FileName: spi_mpc83xx.h$
* $Version : 3.8.1.0$
* $Date    : May-12-2011$
*
* Comments:
*
*   This file contains the definitions of constants and structures
*   required for the SPI driver for the MPC83xx
*
*END*********************************************************************/


/*--------------------------------------------------------------------------*/
/*
**                            CONSTANT DEFINITIONS
*/

#define SPI

/* 
** IOCTL calls specific to mpc83xx SPI 
*/
#define IO_IOCTL_SPI_GET_TRANSFER_SIZE     _IO(IO_TYPE_SPI,0x19)   /* mpc83xx */
#define IO_IOCTL_SPI_SET_TRANSFER_SIZE     _IO(IO_TYPE_SPI,0x20)   /* mpc83xx */
#define IO_IOCTL_SPI_SET_CHIP_SELECT       _IO(IO_TYPE_SPI,0x21)   /* mpc83xx */
#define IO_IOCTL_SPI_CLEAR_CHIP_SELECT     _IO(IO_TYPE_SPI,0x22)   /* mpc83xx */
#define IO_IOCTL_SPI_FLUSH                 _IO(IO_TYPE_SPI,0x23)   /* mpc83xx  no flush */

/* 
** SPI device modes of operation specific to mpc83xx SPI 
*/
#define SPI_DEVICE_LPBACK_MODE			   (0x04)

/* SPI Error Codes specific to mpc83xx SPI  */
#define SPI_ERROR_TRANSFER_SIZE_INVALID    (SPI_ERROR_BASE | 0x08)
#define SPI_ERROR_CHIPSELECT_INVALID       (SPI_ERROR_BASE | 0x09)

#define SPI_CS0         0x00
#define SPI_CS1			0x01
#define SPI_CS2			0x02
#define SPI_CS3			0x03


/*--------------------------------------------------------------------------*/
/*
**                    DATATYPE DECLARATIONS
*/

/*
** MPC83xx_SPI_INIT_STRUCT
**
** This structure defines the initialization parameters to be used
** when a serial port is initialized.
*/
typedef struct mpc83xx_spi_init_struct
{

   /* spi channel number */
   uint_32 CHANNEL;

   /* The SPI default chip select */
   uint_32 CS; 
   
   /* The SPI transfer mode */
   uint_32 TRANSFER_MODE;

   /* The Baud rate for the channel */
   /* The baud rate for the channel */
   uint_32 BAUD_RATE; //CSBCLK/div, div: multiples of 4
                      // div must be in the range 4 - 1024

   /* The maximum size of each receive buffer */
//   uint_32 QUEUE_SIZE;

    /* The maximum size of each receive */
   uint_32 RX_BUFFER_SIZE;

   /* The maximum size of each transmit */
   uint_32 TX_BUFFER_SIZE;
   
  /* The interrupt vector to use if interrupt driven */
   uint_32 VECTOR;

   /* SPI Data transfer LSB first or MSB first? 
      one of SPI_DEVICE_BIG_ENDIAN / SPI_DEVICE_LITTLE_ENDIAN */
   uint_32 ENDIAN;
   
   /* Character length, 4 - 16 & 32 */
   uint_32 CHAR_LEN;
   
   /* The SPI clock phase and polarity mode */
   uint_32 CLOCK_POL_PHASE;
   
   /* Output pins open drain? */
   boolean OPEN_DRAIN;
   
   /* Time-Out in ticks used while transmission/Reception */
   uint_32 TIME_OUT;

} MPC83xx_SPI_INIT_STRUCT, _PTR_ MPC83xx_SPI_INIT_STRUCT_PTR;


/*
** MPC83xx_SPI_INFO_STRUCT
** Run time state information for each serial channel
*/
typedef struct mpc83xx_spi_info_struct
{

   /* Current initialized values */
   MPC83xx_SPI_INIT_STRUCT  INIT;

   /* device register structure pointer */
   pointer                  DEV_REG_PTR;

   /* The interrupt vector to use if interrupt driven */
   uint_32                  VECTOR;

   /* The previous interrupt handler and data */
   void       (_CODE_PTR_ OLD_ISR)(pointer);
   void       (_CODE_PTR_ OLD_ISR_EXCEPTION_HANDLER)(_mqx_uint, _mqx_uint,
      pointer, pointer);
   pointer                OLD_ISR_DATA;

   /* Receive/transmit flag */
   uint_16                           RECEIVING;
   
   /* Difference between transmitted and received bytes */
   uint_16                           ONTHEWAY;
   
   /* Number of bytes requested to receive */
   uint_32                           RX_REQUEST;
  
   /* Pointer to the buffer to use for Tx/Rx data */
   uchar_ptr                         RX_BUFFER;

   /* Rx write index */
   volatile uint_32                  RX_IN;

   /* Rx read index */
   volatile uint_32                  RX_OUT;

   /* Pointer to the buffer to use for current Tx data */
   uchar_ptr                         TX_BUFFER;

   /* Tx write index */
   uint_32                           TX_IN;

   /* Tx read index */
   uint_32                           TX_OUT;

   /* Chip select used during transfers */
   uint_16                           CS;

   /* Previous state of chip select */
   uint_16                           CS_ENABLED;

   /* Chip select set callback */
   SPI_CS_CALLBACK                   CS_CALLBACK;

   /* User data for callback */
   pointer                           CS_USERDATA;

  /* Statistical information */
   SPI_STATISTICS_STRUCT             STATS;
   
} MPC83xx_SPI_INFO_STRUCT, _PTR_ MPC83xx_SPI_INFO_STRUCT_PTR; 


/*--------------------------------------------------------------------------*/
/* 
**                        FUNCTION PROTOTYPES
*/

#ifdef __cplusplus
extern "C" {
#endif

extern uint_32 _mpc83xx_spi_polled_install(char_ptr, pointer);
extern uint_32 _mpc83xx_spi_int_install(char_ptr, pointer);

#ifdef __cplusplus
}
#endif

#endif
/* EOF */
